<?php
defined('IN_CMS') or exit('No permission resources.');
pc_base::load_app_class('admin','admin',0);
class crud extends admin  {
	function __construct() {
        parent::__construct();
		$this->db = pc_base::load_model("myassorttype_model");
	}
	
	/**
	 * 列表
	 */
	function mylist(){
		$page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;

        switch ($_POST['action']){
            case "add":
                $id = $this->db->insert($_POST['item'],true);
                break;
            case "edit":
                $id = $_POST['id'];
                $this->db->update($_POST['item'],$where = 'id = '.$id);
                break;
        }

		$whereSql = " 1 = 1 ";
        $lists = $this->db->listinfo($whereSql,$order = 'id DESC',$page);

		$pages = $this->db->pages;
		
		include $this->admin_tpl('mylist');
	}
	
	
	function myadd(){
        $whereSql = " 1 = 1 ";
        $lists = $this->db->select($whereSql);
		include $this->admin_tpl('myadd');
		
	}
	
	function myedit(){
        $whereSql = " 1 = 1 ";
        $lists = $this->db->select($whereSql);

		$id = $_GET['id'];
		$whereSql = array('id'=>$id);
		$item = $this->db->get_one($whereSql);
		
		include $this->admin_tpl('myedit');
	}

	function myview(){
		$id = $_GET['id'];
		$whereSql = "id = '" . $id . "'";
        $item = $this->db->get_one($whereSql);

		include $this->admin_tpl('myview');
	}
	
	
	function mydelone(){
		$id = $_GET['id'];
		$new['is_del'] = 1;
		$this->db->update($new,$where = 'id = '.$id);
		$this->mylist();
	}
	
	/**
	 * 批量删除
	 */
	function mydel(){
		$ids = $_POST['id'];
		
		if(empty($ids) || !is_array($ids)){
			showmessage(L('没有记录可以删除'),HTTP_REFERER);
		}else{
			foreach ($ids as $id){
				$new['is_del'] = 1;
				$this->db->update($new,$where = 'id = '.$id);
			}
		}
		$this->mylist();
	}

}

?>